<?php
/***********************************************************
我的评论
*************************************************************/

class CommentsAction extends Action {

    public function _initialize() {
        $this->tologin();
    }

    public function index() {
        import("@.ORG.Page");
        C('PAGE_NUMBERS',10);
        $uModel=D('Users');
        $count = D('Comments')->where("user_id='".$this->my['user_id']."'")->count();
        $p= new Page($count,20);
        $page = $p->show('Comments/index/p/');
        $data = D('CommentsView')->where("Comments.user_id='".$this->my['user_id']."'")->order("dateline DESC")->limit($p->firstRow.','.$p->listRows)->select();

        if ($this->my['comments']>0) {
            $uModel->where("user_id='".$this->my['user_id']."'")->setField('comments',0);
        }

        $this->assign('ctent',D('Content'));
        $this->assign('count',$count);
        $this->assign('page',$page);
        $this->assign('data',$data);
        $this->assign('usertemp',usertemp($this->my));
        $this->assign('userside',$uModel->userside($this->my,'userside'));
        $this->assign('subname','收到的评论');
        $this->assign('type','comments');
        $this->display();
    }

    public function sendlist() {
        import("@.ORG.Page");
        C('PAGE_NUMBERS',10);
        $uModel=D('Users');
        $count = D('Comments')->where("comment_uid='".$this->my['user_id']."'")->count();
        $p= new Page($count,20);
        $page = $p->show('Comments/sendlist/p/');
        $data = D('CommentslistView')->where("Comments.comment_uid='".$this->my['user_id']."'")->order("dateline DESC")->limit($p->firstRow.','.$p->listRows)->select();

        if ($this->my['comments']>0) {
            $uModel->where("user_id='".$this->my['user_id']."'")->setField('comments',0);
        }

        $this->assign('ctent',D('Content'));
        $this->assign('count',$count);
        $this->assign('page',$page);
        $this->assign('data',$data);
        $this->assign('usertemp',usertemp($this->my));
        $this->assign('userside',$uModel->userside($this->my,'userside'));
        $this->assign('subname','发出的评论');
        $this->assign('type','comments');
        $this->display();
    }

    public function delmsg() {
        $cmid=$_GET['cmid'];
        D('Comments')->where("comment_id='$cmid' AND (user_id='".$this->my['user_id']."' OR comment_uid='".$this->my['user_id']."')")->delete();
        echo 'success';
    }

    private function tologin() {
        if (!$this->my) {
            echo '<script type="text/javascript">window.location.href="'.SITE_URL.'/login"</script>';
            exit;
        }
    }
}
?>